package com.jike.mahjong.task.quartz;

import com.google.gson.Gson;
import com.jike.mahjong.common.Constants;
import com.jike.mahjong.common.util.HttpUtil;
import com.jike.mahjong.model.RequestMethod;
import com.jike.mahjong.model.RequestModel;
import com.jike.mahjong.task.JobConstants;
import org.quartz.*;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by star on 2017/1/11.
 */
public class MsgSendTask implements Job {

    private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        JobKey key = context.getJobDetail().getKey();
        JobDataMap dataMap = context.getJobDetail().getJobDataMap();
        String jobSays = dataMap.getString(JobConstants.JOB_DATA_KEY);

        List<String> args = new ArrayList<String>();
        RequestModel requestModel = new RequestModel();
        requestModel.setCmd(RequestMethod.sendNotice);
        args.add(jobSays);
        requestModel.setArgs(args);
        System.out.println(jobSays + sdf.format(new Date()));
        Gson gson = new Gson();
        String paraStr = gson.toJson(requestModel);
        if(Constants.envFlag){
        	String result = HttpUtil.PostWithJson(Constants.BACK_URL, paraStr);
        }
        System.out.println(paraStr);


    }
}
